package ig.metrica.ui.modelo;

//import ig.metrica.Modelo;
import ig.metrica.ModeloSBean;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.JOptionPane;
import ig.metrica.ui.PantallaBusquedaSevinproPanel;
import ig.metrica.ui.ServiceLocator;
import ig.metrica.ui.WizzardSevinproPanel;
import ig.util.ConexionServer;
import ig.util.ejb.IGBean;
import java.util.Properties;
import javax.naming.Context;

public class PantallaBusquedaModelo extends PantallaBusquedaSevinproPanel {
    
    private PantallaDatosBasicosModelo panel;
    private String[] titulos;
    private ArrayList datos;
    
    public PantallaBusquedaModelo( PantallaDatosBasicosModelo panel, WizzardSevinproPanel wizzard){
        super(panel, wizzard, new ModeloTablaResultadoBusquedaModelo(new String[] {"Nombre"}, new ArrayList()) );
        this.panel = panel;
        this.datos = new ArrayList();
        ((ModeloTablaResultadoBusquedaModelo)tabla.getModel()).setDatos( datos );
    }
    //ig.metrica.ModeloSRemote modeloSB=null;
    private ig.metrica.ModeloSBean lookupModeloSBean() {
        /*try {
            if(modeloSB==null){
                Properties prop = new Properties();
                prop.put( Context.INITIAL_CONTEXT_FACTORY, IGBean.INITIAL_CONTEXT_FACTORY);
                String Sockec = new ConexionServer().getSocketServer();
                prop.put( Context.PROVIDER_URL, Sockec);
                
                javax.naming.Context c = new javax.naming.InitialContext(prop);
                Object remote = c.lookup("ModeloSBean");
                ig.metrica.ModeloSRemoteHome rv = (ig.metrica.ModeloSRemoteHome) javax.rmi.PortableRemoteObject.narrow(remote, ig.metrica.ModeloSRemoteHome.class);
                modeloSB =rv.create();
            }
            return modeloSB;
        } catch(javax.naming.NamingException ne) {
//            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
            throw new RuntimeException(ne);
        } catch(javax.ejb.CreateException ce) {
//            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce);
            throw new RuntimeException(ce);
        } catch(java.rmi.RemoteException re) {
//            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,re);
            throw new RuntimeException(re);
        }*/
        return new ModeloSBean();
    }
    
    protected void accionBuscar(){
        datos = new ArrayList();
        try {
            Collection lista = this.lookupModeloSBean().findAll();
//            Collection lista = ServiceLocator.getInstancia().getModelos();
//                listaFull = ServiceLocator.getInstancia().getModelos();Modelo
            listaFull=lista;
            Iterator i = lista.iterator();
            while (i.hasNext()){
                Object[] registro = new Object[6];
//                String nom = ((Modelo)i.next()).getNombre().trim();
//                if(nom !=null)
//                    registro[0] = nom;
                registro[0] = i.next();
                datos.add( registro );
            }
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog( this,"Error:"+ e.toString(),"Mensaje",JOptionPane.OK_CANCEL_OPTION );
        }
        ((ModeloTablaResultadoBusquedaModelo)tabla.getModel()).setDatos( datos );
    }
}


